class FilePreviewActivity : AppCompatActivity() {
    private lateinit var binding: ActivityFilePreviewBinding
    private val viewModel: FilePreviewViewModel by viewModels()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityFilePreviewBinding.inflate(layoutInflater)
        setContentView(binding.root)

        val fileUri = intent.getParcelableExtra<Uri>(EXTRA_FILE_URI)
        fileUri?.let { setupPreview(it) }
    }

    private fun setupPreview(uri: Uri) {
        when (getFileType(uri)) {
            FileType.IMAGE -> showImagePreview(uri)
            FileType.VIDEO -> showVideoPreview(uri)
            FileType.AUDIO -> showAudioPreview(uri)
            FileType.DOCUMENT -> showDocumentPreview(uri)
        }
    }

    private fun showImagePreview(uri: Uri) {
        binding.imagePreview.visibility = View.VISIBLE
        Glide.with(this)
            .load(uri)
            .into(binding.imagePreview)
    }

    private fun showVideoPreview(uri: Uri) {
        binding.videoPlayer.visibility = View.VISIBLE
        binding.videoPlayer.setVideoURI(uri)
        binding.videoPlayer.start()
    }

    private fun showAudioPreview(uri: Uri) {
        binding.audioPlayer.visibility = View.VISIBLE
        binding.audioPlayer.setDataSource(uri.toString())
        binding.audioPlayer.prepare()
    }

    companion object {
        const val EXTRA_FILE_URI = "extra_file_uri"
    }
} 